package cn.com.smart.api.form.controller;

import cn.com.smart.bean.SmartResponse;
import cn.com.smart.filter.bean.FilterParam;
import cn.com.smart.form.bean.entity.TForm;
import cn.com.smart.form.controller.BaseFormController;
import cn.com.smart.form.service.FormImportService;
import cn.com.smart.form.service.FormService;
import cn.com.smart.web.bean.RequestPage;
import cn.com.smart.web.service.OPService;
import com.mixsmart.utils.StringUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;

/**
 * Copyright
 *
 * @author chenwenchao
 * @date 2019/4/3
 * Description:
 */
@Controller
@Api(tags = "表单模块", description = "表单模块模块")
@RequestMapping("/api/form")
public class FormApiController extends BaseFormController {

    private static final String VIEW_DIR = "form";

    @Autowired
    private FormService formServ;
    @Autowired
    private OPService opServ;
    @Autowired
    private FormImportService formImportServ;

    /**
     * 表单列表
     * @param request
     * @param searchParam
     * @param page
     * @return
     * @throws Exception
     */
    @ApiOperation("获取表单list")
    @RequestMapping(value = "/list",method = RequestMethod.GET)
    public @ResponseBody
    SmartResponse<Object> list(HttpServletRequest request,FilterParam searchParam, RequestPage page) throws Exception {
        SmartResponse<Object> smartResp = opServ.getDatas("form_mgr_list",searchParam,page.getStartNum(), page.getPageSize());

        return  smartResp;
    }


    /**
     * 查看表单
     * @param id
     * @return
     * @throws Exception
     */
    @ApiOperation("获取表单html信息")
    @RequestMapping(value = "/show",method = RequestMethod.GET)
    public @ResponseBody SmartResponse<Object>  show(String id) throws Exception {
        SmartResponse<Object> smartResp = new SmartResponse<Object>();
        if(StringUtils.isNotEmpty(id)) {
            smartResp = formServ.find(TForm.class, id);
        }
        return smartResp;
    }
}
